package com.qfedu.scode.controller;

import com.qfedu.scode.config.SystemConfig;
import com.qfedu.scode.dto.UserDto;
import com.qfedu.scode.entity.User;
import com.qfedu.scode.service.intf.UserService;
import com.qfedu.scode.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: StartCoding
 * @description: 一款真正的后端源码生成器，助力轻松入门Java程序
 * @author: Feri(老邢)
 * @create: 2021-01-06 11:09:45
 */
@RestController
@RequestMapping("api/user/")
@Api(tags = "实现User各种操作")
public class UserController{

    /*
    *注入业务逻辑层对象*/
    @Autowired
    private UserService service;
    /*
    * 新增内容*/
    @ApiOperation(value = "实现新增",notes = "实现新增")
    @PostMapping("save.do")
    public R save(@RequestBody UserDto dto){
       return service.register(dto);
    }

    /*
    * 查询 所有数据*/
    @ApiOperation(value = "实现全部查询",notes = "实现全部查询")
    @GetMapping("all.do")
    public R all(){
       return service.queryAll();
    }

    /*
     * 登陆*/
    @ApiOperation(value = "完成登陆",notes = "完成登陆")
    @PostMapping("login.do")
    public R login(@RequestBody UserDto dto){
        return service.login(dto);
    }

    /*
     * 校验 令牌的有效性*/
    @ApiOperation(value = "实现令牌有效性校验",notes = "实现令牌有效性校验")
    @GetMapping("checktoken.do")
    public R checkToken(HttpServletRequest request){
        return service.checkToken(request.getHeader(SystemConfig.TOKEN_HEADER));
    }
}